
const express = require('express')
const router = express.Router()

// 获取盘点任务
router.get('/tasks', (req, res) => {
  const tasks = [
    {
      id: 'IT20241101001',
      store: '朝阳门店',
      items: [
        { name: '有机蔬菜', expected: 100, actual: 99, diff: -1 },
        { name: '精品水果', expected: 50, actual: 51, diff: 1 }
      ],
      status: '已完成',
      diffRate: 0.67,
      createdAt: '2024-11-01 09:00:00'
    }
  ]
  res.json(tasks)
})

// 创建盘点任务
router.post('/tasks', (req, res) => {
  const { storeId, items } = req.body
  
  const task = {
    id: `IT${Date.now()}`,
    storeId,
    items,
    status: '待盘点',
    createdAt: new Date().toLocaleString('zh-CN')
  }
  
  res.json({ success: true, task })
})

// 提交盘点结果
router.post('/submit', (req, res) => {
  const { taskId, actualCounts } = req.body
  
  // 计算差异
  const result = {
    taskId,
    diffRate: 0.8,
    status: '已完成',
    completedAt: new Date().toLocaleString('zh-CN')
  }
  
  res.json({ success: true, result })
})

module.exports = router
